﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Baimasoft.FrameWork.Base;
using Baimasoft.Manage.SqlServerDAL;

public partial class SysManage_PasswordSet : System.Web.UI.Page
{
    BaimasoftFile MyFile = new BaimasoftFile();
    DeptPersManage MyDPM = new DeptPersManage();

    protected string UserLogonID = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((string)Session["Baimasoft_User_LogonID"] == null)
        {
            Response.Redirect("../ReLogon.aspx");
        }
        else
        {
            UserLogonID = (string)Session["Baimasoft_User_LogonID"];
        }
    }
    protected void SetPsd_Click(object sender, EventArgs e)
    {
        if (OldPassword.Text.ToString ().Trim () == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('旧密码不能为空!');</script>");
            return;
        }
        if (NewPassword.Text.ToString().Trim() == "" || NewPassword.Text.ToString().Trim().Length < 6)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新密码不能为空且长度不小于6!');</script>");
            return;
        }

        string sOldPsdMd5 = MyFile .Md5 (OldPassword.Text.ToString().Trim());
        int back1 = MyDPM .ModPassword (UserLogonID, sOldPsdMd5);
        if (back1 == 1)
        {
            string sNewPsdMd5 = MyFile .Md5 (NewPassword.Text.ToString().Trim());
            int back2 = MyDPM .ModPassword (UserLogonID, sOldPsdMd5, sNewPsdMd5);
            if (back2 == 1)
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改密码成功!');</script>");
            else
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改密码失败!');</script>");
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您输入的旧密码不正确!');</script>");
        }
    }

}
